public class Demo17 {
    public static void main(String[] args) {
        Thread t1 = new Thread(()->{
            for(int i = 0;i < 5;i++){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
            System.out.println("t1线程执行完毕!");
        });

        Thread t2 = new Thread(()->{
            try {
                // join()在哪个线程中,哪个线程就会等待调用join()的线程先执行完毕,该线程才能继续执行
                t1.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("t2线程执行完毕!");
        });

        t1.start();
        t2.start();

        System.out.println("主线程执行完毕!");
    }
}
